import openai
from openai import OpenAI

# 设置你的 OpenAI API Key
client = OpenAI(
    api_key="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"
)


# 设置你的OpenAI API Key
def chat_with_gpt(prompt):
    try:
        response = client.chat.completions.create(
            model="gpt-3.5-turbo",  # 也可以使用 "gpt-4"
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": prompt}
            ]
        )
        return response.choices[0].message.content
    except Exception as e:
        return f"发生错误：{e}"


if __name__ == "__main__":
    user_input = input("你想说：")
    reply = chat_with_gpt(user_input)
    print(f"AI：{reply}")
